//
//  ZH_BottomInfoTableViewCell.m
//  WisdomStar
//
//  Created by zhangliwen on 2018/10/25.
//  Copyright © 2018年 zhangliwen. All rights reserved.
//

#import "ZH_BottomInfoTableViewCell.h"
@interface ZH_BottomInfoTableViewCell()
@property (nonatomic,weak)UIImageView *images;
@property (nonatomic,weak)UILabel *priceLabel;
@property (nonatomic,weak)UILabel *titleLabel;
@property (nonatomic,weak)UILabel *teacherLabel;
@property (nonatomic,weak)UIButton *typeButton;
@property (nonatomic,weak)UIButton *classButton;
@property (nonatomic,weak)UIButton *gradeButton;
@property (nonatomic,weak)UILabel *timeLabel;
@property (nonatomic,weak)UILabel *timeLabels;
@end
@implementation ZH_BottomInfoTableViewCell

///创建
+(instancetype)cellWithTableView:(UITableView*)tableView
{
    static NSString *ID = @"ZH_BottomInfoTableViewCell";
    ZH_BottomInfoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if(cell == nil){
        cell = [[ZH_BottomInfoTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    return cell;
}
///初始化
-(void)initDefault
{
    [self unShowClickEffect];
     self.bottomShortLineImage.hidden = NO;
}
- (void)loadSubviewConstraints{
    [self.images mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(FITSCALE(14));
        make.left.equalTo(self.contentView.mas_left).offset(FITSCALE(12));
        make.width.mas_equalTo(FITSCALE(105));
        make.height.mas_equalTo(FITSCALE(102));
        make.bottom.equalTo(self.contentView).offset(FITSCALE(-15));
    }];
    [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.images);
        make.right.equalTo(self.contentView).offset(FITSCALE(-12));
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.images);
        make.left.equalTo(self.images.mas_right).offset(FITSCALE(17));
        make.right.equalTo(self.priceLabel.mas_left);
    }];
    [self.teacherLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom).offset(FITSCALE(19));
        make.left.equalTo(self.titleLabel);
    }];
    [self.typeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom).offset(FITSCALE(14));
        make.left.equalTo(self.teacherLabel.mas_right).offset(FITSCALE(10));
        make.width.mas_equalTo(FITSCALE(85));
        make.height.mas_equalTo(FITSCALE(22));
    }];
    [self.classButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.teacherLabel.mas_bottom).offset(FITSCALE(12));
        make.left.equalTo(self.titleLabel);
        make.width.mas_equalTo(FITSCALE(44));
        make.height.mas_equalTo(FITSCALE(22));
    }];
    [self.gradeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.teacherLabel.mas_bottom).offset(FITSCALE(12));
        make.left.equalTo(self.classButton.mas_right).offset(FITSCALE(9));
        make.width.mas_equalTo(FITSCALE(51));
        make.height.mas_equalTo(FITSCALE(22));
    }];
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.priceLabel.mas_bottom).offset(FITSCALE(19));
        make.right.equalTo(self.contentView).offset(FITSCALE(-12));
    }];
    [self.timeLabels mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.teacherLabel);
        make.top.equalTo(self.classButton.mas_bottom).offset(FITSCALE(11));
    }];
}
- (void)updataUI:(NSMutableDictionary *)data{
    if (data) {
        [self.images sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",SERVER_TEST,data[@"image"]]] placeholderImage:nil];
        self.priceLabel.text = [NSString stringWithFormat:@"￥%@/小时",data[@"price"]];
        self.titleLabel.text = data[@"name"];
        self.teacherLabel.text = data[@"nickname"];
        NSString *string = [NSString stringWithFormat:@"%@",data[@"teach_type"]];
        if ([string isEqualToString:@"1"]) {
            [self.typeButton setTitle:@"一对一授课" forState:UIControlStateNormal];
        }
        else{
            [self.typeButton setTitle:@"团体课程" forState:UIControlStateNormal];
        }
        [self.classButton setTitle:data[@"cate_name"] forState:UIControlStateNormal];
        [self.gradeButton setTitle:data[@"level"] forState:UIControlStateNormal];
        self.timeLabel.text = data[@"create_at"];
        self.timeLabels.text = [NSString stringWithFormat:@"授课时间: %@",data[@"start"]];
    }
}
#pragma mark - getter,setter
- (UIImageView *)images{
    if (!_images) {
        UIImageView *image = [UIImageView createImageViewWithName:@""];
        image.backgroundColor = kFontColorRed;
        image.layer.cornerRadius = FITSCALE(3);
        image.layer.masksToBounds = YES;
        image.clipsToBounds = YES;
        [self.contentView addSubview:_images = image];
    }
    return _images;
}
- (UILabel *)priceLabel{
    if (!_priceLabel) {
        UILabel *label = [UILabel createLabelWithText:@"￥400元/小时" font:kFontSize_26];
        label.textColor = [UIColor colorWithHexString:@"#FF4242"];
        label.textAlignment = NSTextAlignmentRight;
        [self.contentView addSubview:_priceLabel = label];
    }
    return _priceLabel;
}
- (UILabel *)titleLabel{
    if (!_titleLabel) {
        UILabel *label = [UILabel createLabelWithText:@"课程标题..." font:kFontSize_26];
        [self.contentView addSubview:_titleLabel = label];
    }
    return _titleLabel;
}
- (UILabel *)teacherLabel{
    if (!_teacherLabel) {
        UILabel *label = [UILabel createLabelWithText:@"李老师" font:kFontSize_26];
        label.textColor = [UIColor colorWithHexString:@"#555555"];
        [self.contentView addSubview:_teacherLabel = label];
    }
    return _teacherLabel;
}
- (UIButton *)typeButton{
    if (!_typeButton) {
        UIButton *button = [UIButton createNoBgButtonWithTitle:@"一对一授课" target:self action:nil];
        [button setTitleColor:[UIColor colorWithHexString:@"#00C9AE"] forState:UIControlStateNormal];
        button.layer.cornerRadius = FITSCALE(10);
        button.layer.borderWidth = FITSCALE(1);
        button.layer.borderColor = [UIColor colorWithHexString:@"#00C9AE"].CGColor;
        button.layer.masksToBounds = YES;
        button.clipsToBounds = YES;
        button.titleLabel.font = kFontSize_26;
        [self.contentView addSubview:_typeButton = button];
    }
    return _typeButton;
}
- (UIButton *)classButton{
    if (!_classButton) {
        UIButton *button = [UIButton createNoBgButtonWithTitle:@"文学" target:self action:nil];
        button.backgroundColor = [UIColor colorWithHexString:@"#CBFFF8"];
        [button setTitleColor:[UIColor colorWithHexString:@"#00C9AE"] forState:UIControlStateNormal];
        button.layer.cornerRadius = FITSCALE(10);
        button.layer.borderWidth = FITSCALE(1);
        button.layer.borderColor = [UIColor colorWithHexString:@"#00C9AE"].CGColor;
        button.layer.masksToBounds = YES;
        button.clipsToBounds = YES;
        button.titleLabel.font = kFontSize_26;
        [self.contentView addSubview:_classButton = button];
    }
    return _classButton;
}
- (UIButton *)gradeButton{
    if (!_gradeButton) {
        UIButton *button = [UIButton createNoBgButtonWithTitle:@"V2中级" target:self action:nil];
        button.backgroundColor = [UIColor colorWithHexString:@"#FFD2CB"];
        [button setTitleColor:[UIColor colorWithHexString:@"#FF4646"] forState:UIControlStateNormal];
        button.layer.cornerRadius = FITSCALE(10);
        button.layer.borderWidth = FITSCALE(1);
        button.layer.borderColor = [UIColor colorWithHexString:@"#FF4646"].CGColor;
        button.layer.masksToBounds = YES;
        button.clipsToBounds = YES;
        button.titleLabel.font = kFontSize_26;
        [self.contentView addSubview:_gradeButton = button];
    }
    return _gradeButton;
}
- (UILabel *)timeLabel{
    if (!_timeLabel) {
        UILabel *label = [UILabel createLabelWithText:@"50秒前" font:kFontSize_24];
        label.textColor = [UIColor colorWithHexString:@"#555555"];
        label.textAlignment = NSTextAlignmentRight;
        [self.contentView addSubview:_timeLabel = label];
    }
    return _timeLabel;
}
- (UILabel *)timeLabels{
    if (!_timeLabels) {
        UILabel *label = [UILabel createLabelWithText:@"授课时间: 2018-10-12 14：00: 00" font:kFontSize_26];
        label.textColor = [UIColor colorWithHexString:@"#999999"];
        [self.contentView addSubview:_timeLabels = label];
    }
    return _timeLabels;
}
@end
